﻿/**
 * @fileOverview 罩层类
 * @copyright (c) 2012 (condenast.com.cn)
 * @author jianjun.wang@condenast.com.cn
 * @version 1.0
 * @depend jquery.js
 */
 
if(typeof CNC=="undefined" || !CNC){
	var CNC = {};
} 

if(typeof CNC.ui=="undefined" || !CNC.ui){
	CNC.ui = {};
} 

(function($){
	/**
	 * 页面遮罩层
	 * @class 遮罩层类
	 * @name CNC.ui.Mask
	 * @param {object} config {maskOpacity:(float)透明度(0.1-1)，默认为0.1,maskColor:(string)罩层颜色，默认为#000}
	 */
	CNC.ui.Mask = function(config){
		this.config = {
			maskOpacity: 0.2,
			maskColor: '#000'
		};
		$.extend(this.config, config);
		this.mask = null;
	}
	CNC.ui.Mask.prototype={
	/**
	 * 显示罩层  
	 */
	show:function(){
		this.mask = $('<div class="jrj-dialog-mask"></div>');
		this.mask.appendTo("BODY");
		this.mask.css({
			position: 'absolute',
			zIndex: 9000,
			top: '0px',
			left: '0px',
			width: $(window).width(),
			height: $(document).height(),
			background: this.config.maskColor,
			opacity: this.config.maskOpacity
		});
		if(navigator.appVersion.indexOf("MSIE 6.0") != -1){
		   this.mask.bgiframe();
		}
		/**
		 * @inner resize事件句柄
		 */
		this.winResizeHandler = function(event){
			 var thisObj = event.data.obj;
			 thisObj._resize();
		}
		$(window).bind('resize',{obj:this}, this.winResizeHandler);
	},
	/**
	* 关闭罩层
	*/	  
	close:function(){			  	
		this.mask.remove();
		$(window).unbind("resize",this.winResizeHandler);
	},
	/**
	 * @private
	 * 窗口大小变化时重置罩层宽高
	 */
	_resize:function(){
		this.mask.css({
			width: $(window).width(),
			height: $(document).height()
		})
	}
  }
})(jQuery);